<?php

require __DIR__.'/../Connect.php';

use PhpAmqpLib\Message\AMQPMessage;

class Worker
{
    public $exchange = 'direct_exchange';
    public $queue = 'direct_sms_queue';

    public function consume()
    {
        $connect = Connect::getInstance();
        $channel = $connect->channel();


        //$channel->queue_declare('task_queue', false, false, false, false);
        echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
        $callback = function($msg) {
            echo " [x] Received ", $msg->body, "\n";
            usleep(100000);
            $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
            echo 'done';
        };
        $channel->basic_qos(null, 1, null);
        $channel->basic_consume($this->queue, '', false, false, false, false, $callback);

        while(count($channel->callbacks)) {
            $channel->wait();
        }

        $channel->close();
        $connect->close();
    }
}
(new Worker())->consume();
